AC_INIT([monodevelop-codeanalysis], 0.2, [monodevelop-list@lists.ximian.com])
AC_PREREQ(2.53)
AM_INIT_AUTOMAKE([1.9 tar-ustar])
AM_MAINTAINER_MODE

ASSEMBLY_VERSION=0.1.0.0

AC_PATH_PROG(MONO, mono)
AC_PATH_PROG(MCS, gmcs)

if test "x$MONO" = "x" ; then
	AC_MSG_ERROR([Can't find "mono" in your PATH])
fi

if test "x$MCS" = "x" ; then
  AC_MSG_ERROR([Can't find "gmcs" in your PATH])
fi
AC_SUBST(PATH)
AC_SUBST(LD_LIBRARY_PATH)

MONO_REQUIRED_VERSION=2.4
PKG_CHECK_MODULES(UNMANAGED_DEPENDENCIES_MONO,mono >= $MONO_REQUIRED_VERSION, has_mono=true, has_mono=false)

if test "x$has_mono" = "xfalse"; then
   AC_MSG_ERROR([Please install mono version $MONO_REQUIRED_VERSION or later to install MonoDevelop.
Please see http://www.mono-project.org/ to download latest mono sources or packages])
fi

if test "x$has_mono" = "xtrue"; then
    if test `uname -s` = "Darwin"; then
	AC_PATH_PROG(RUNTIME, mono, no)
	AC_PATH_PROG(CSC, gmcs, no)
	LIB_PREFIX=
	LIB_SUFFIX=.dylib
    else
	AC_PATH_PROG(RUNTIME, mono, no)
	AC_PATH_PROG(CSC, gmcs, no)
	LIB_PREFIX=.so
	LIB_SUFFIX=
    fi
fi

# Find msgfmt and msgmerge for translations
AC_PATH_PROG(MSGFMT, msgfmt, no)
if test "x$MSGFMT" = "xno"; then
        AC_MSG_ERROR([You need to install msgfmt from intltool])
fi
AC_PATH_PROG(MSGMERGE, msgmerge, no)
if test "x$MSGMERGE" = "xno"; then
        AC_MSG_ERROR([You need to install msgmerge from intltool])
fi

dnl hard dependencies
MONOADDINS_REQUIRED_VERSION=0.4
MONODEVELOP_REQUIRED_VERSION=1.9.1
GTKSHARP_REQUIRED_VERSION=2.12.2
CECIL_VERSION=0.5
GENDARME_VERSION=1.9

PKG_CHECK_MODULES(MONO_ADDINS, mono-addins >= $MONOADDINS_REQUIRED_VERSION)
AC_SUBST(MONO_ADDINS_LIBS)
PKG_CHECK_MODULES(MONO_ADDINS_SETUP, mono-addins-setup >= $MONOADDINS_REQUIRED_VERSION)
AC_SUBST(MONO_ADDINS_SETUP_LIBS)
PKG_CHECK_MODULES(MONO_ADDINS_GUI, mono-addins-gui >= $MONOADDINS_REQUIRED_VERSION)
AC_SUBST(MONO_ADDINS_GUI_LIBS)
PKG_CHECK_MODULES(GLIB_SHARP, glib-sharp-2.0 >= $GTKSHARP_REQUIRED_VERSION)
AC_SUBST(GLIB_SHARP_LIBS)
PKG_CHECK_MODULES(GTK_SHARP, gtk-sharp-2.0 >= $GTKSHARP_REQUIRED_VERSION)
AC_SUBST(GTK_SHARP_LIBS)
PKG_CHECK_MODULES(MONODEVELOP, monodevelop >= $MONODEVELOP_REQUIRED_VERSION)
AC_SUBST(MONODEVELOP_LIBS)

gtksharp_prefix="`$PKG_CONFIG --variable=prefix gtk-sharp-2.0`"
AC_SUBST(gtksharp_prefix)

CSC_FLAGS="-debug -codepage:utf8"

AC_SUBST(LIB_SUFFIX)
AC_SUBST(LIB_PREFIX)
AC_SUBST(ASSEMBLY_VERSION)
AC_SUBST(CSC_FLAGS)

MD_DIR='$(prefix)/lib/monodevelop'
MD_ASSEMBLY_DIR="$MD_DIR/bin"
MD_ADDIN_DIR="$MD_DIR/AddIns"

AC_SUBST(MD_ASSEMBLY_DIR)
AC_SUBST(MD_ADDIN_DIR)
AC_SUBST(MD_DIR)

AC_OUTPUT([
Makefile
monodevelop-codeanalysis.pc
MonoDevelop.CodeAnalysis/Makefile
MonoDevelop.CodeAnalysis.Gendarme/Makefile
MonoDevelop.CodeAnalysis.Smokey/Makefile
])

echo ""
echo "Configuration summary"
echo ""
echo "   * Installation prefix = $prefix"
echo "   * C# compiler = $CSC"
echo ""
